home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / quake.zip / HIPGRAPL.ZIP / HIPTRAIN.QC < prev    next >
Text File  |  1997-01-16  |  5KB  |  206 lines

  1. /* Train QuickC program
  2.    By Jim Dose'  9/11/96
  3.    Copyright (c)1996 Hipnotic Interactive, Inc.
  4.    All rights reserved.
  5.    Do not distribute.
  6. */
  7.  
  8. void() train_blocked;
  9. void() func_train;
  10. void() hip_train_next;
  11. void() hip_func_train_find;
  12.  
  13. void() hip_train_use =
  14. {
  15.     if (self.think != hip_func_train_find)
  16.         {
  17.         if ( self.velocity != '0 0 0' )
  18.             return;        // already activated
  19.         }
  20.     hip_train_next();
  21. };
  22.  
  23. void() hip_train_wait =
  24.     {
  25.     if (self.wait)
  26.         {
  27.       sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  28.       if ( self.wait != -1 )
  29.             {
  30.             self.nextthink = self.ltime + self.wait;
  31.             self.wait = 0;
  32.          }
  33.         }
  34.     else
  35.         self.nextthink = self.ltime + 0.1;
  36.  
  37.     self.think = hip_train_next;
  38.     };
  39.  
  40.  
  41. void() hip_train_next =
  42. {
  43.     local entity    targ;
  44.     local float        current;
  45.    local string   temp;
  46.  
  47.     // Get the speed of the current path_corner.
  48.     // (we must save this off at each path change since
  49.     // we don't have a pointer to the current path_corner).
  50.     current = self.cnt;
  51.  
  52.     targ = find (world, targetname, self.target);
  53.  
  54.     // Save the speed in cnt for later use
  55.     self.cnt = targ.speed;
  56.     self.target = targ.target;
  57.     if (!self.target)
  58.         objerror ("hip_train_next: no next target");
  59.  
  60.     sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  61.  
  62.     self.wait = targ.wait;
  63.      if (targ.wait)
  64.         {
  65.         self.think = hip_train_wait;
  66.         }
  67.     else
  68.         {
  69.         self.think = hip_train_next;
  70.         }
  71.  
  72.    if ( self.goalentity.event )
  73.       {
  74.       // Trigger any events that should happen at the corner.
  75.       temp = self.target;
  76.       self.target = self.goalentity.event;
  77.       self.message = self.goalentity.message;
  78.       SUB_UseTargets();
  79.       self.target = temp;
  80.       self.message = string_null;
  81.       }
  82.  
  83.    // Save the current entity
  84.    self.goalentity = targ;
  85.  
  86.     if ( current == -1 )
  87.         {
  88.         // Warp to the next path_corner
  89.       setorigin (self, targ.origin - self.mins );
  90.         self.nextthink = self.ltime + 0.01;
  91.         }
  92.     else
  93.         {
  94.         // check if there's a speed change
  95.         if (current>0)
  96.             self.speed = current;
  97.  
  98.         // travel to the next path change
  99.         SUB_CalcMove (targ.origin - self.mins, self.speed, self.think );
  100.         }
  101.     };
  102.  
  103. void() hip_func_train_find =
  104.  
  105. {
  106.     local entity    targ;
  107.  
  108.     targ = find (world, targetname, self.target);
  109.  
  110.    // Save the current entity
  111.    self.goalentity = targ;
  112.  
  113.    // Save the speed in cnt for later use
  114.     self.cnt = targ.speed;
  115.  
  116.     self.target = targ.target;
  117.     setorigin (self, targ.origin - self.mins);
  118.     if (!self.targetname)
  119.     {    // not triggered, so start immediately
  120.         self.nextthink = self.ltime + 0.1;
  121.         self.think = hip_train_next;
  122.     }
  123. };
  124.  
  125. /*QUAKED func_train2 (0 .5 .8) ?
  126. This is a modification of the standard func_train entity.
  127. It is functionally equivalent, except that it removes a slight delay that
  128. would occur after each path entry, and it adds a speed variable to the
  129. path_corner entity.
  130.  
  131. "noise" contains the name of the sound to play when train stops.
  132. "noise1" contains the name of the sound to play when train moves.
  133. Both "noise" and "noise1" defaults depend upon "sounds" variable.
  134.  
  135. In path_corner, set speed to be the new speed of the train after it reaches
  136. the path change.  If speed is -1, the train will warp directly to the next
  137. path change after the specified wait time.
  138.  
  139. Also in path_corner, if wait is set to -1, the train will wait until it is
  140. retriggered before moving on to the next goal.
  141.  
  142. Here is a reiteration of the func_train docs:
  143.  
  144. Trains are moving platforms that players can ride.
  145. The targets origin specifies the min point of the train at each corner.
  146. The train spawns at the first target it is pointing at.
  147. If the train is the target of a button or trigger, it will not begin moving until activated.
  148. speed    default 100
  149. dmg        default    2
  150. sounds
  151. 1) ratchet metal
  152.  
  153. */
  154. void() func_train2 =
  155. {
  156.     if (!self.speed)
  157.         self.speed = 100;
  158.     if (!self.target)
  159.         objerror ("func_train without a target");
  160.     if (!self.dmg)
  161.         self.dmg = 2;
  162.  
  163.    if ( !self.noise )
  164.       {
  165.       if (self.sounds == 0)
  166.          {
  167.          self.noise = ("misc/null.wav");
  168.          }
  169.  
  170.       if (self.sounds == 1)
  171.          {
  172.          self.noise = ("plats/train2.wav");
  173.          }
  174.       }
  175.    if ( !self.noise1 )
  176.       {
  177.       if (self.sounds == 0)
  178.          {
  179.          self.noise1 = ("misc/null.wav");
  180.          }
  181.       if (self.sounds == 1)
  182.          {
  183.          self.noise1 = ("plats/train1.wav");
  184.          }
  185.       }
  186.  
  187.    precache_sound( self.noise );
  188.    precache_sound( self.noise1 );
  189.  
  190.     self.cnt = 1;
  191.     self.solid = SOLID_BSP;
  192.     self.movetype = MOVETYPE_PUSH;
  193.     self.blocked = train_blocked;
  194.    self.use = hip_train_use;
  195.     self.classname = "train2";
  196.  
  197.     setmodel (self, self.model);
  198.     setsize (self, self.mins , self.maxs);
  199.     setorigin (self, self.origin);
  200.  
  201. // start trains on the second frame, to make sure their targets have had
  202. // a chance to spawn
  203.     self.nextthink = self.ltime + 0.1;
  204.    self.think = hip_func_train_find;
  205. };
  206.